﻿using System;
using System.Web.UI;
using Google.Translates.Core;

namespace ml_test_google_trans.Translate
{
    public partial class SimpleTrans : Page
    {
        private const string Request_Model_Http = "Http", Request_Model_Lib = "Lib";
        


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rblRequestModel.Items.Add(Request_Model_Http);
                rblRequestModel.Items.Add(Request_Model_Lib);
                rblRequestModel.SelectedIndex = 0;
                rblBreakSentencesModel.Items.Add(StringHelper.Break_Sentences_Model_Mine);
                rblBreakSentencesModel.Items.Add(StringHelper.Break_Sentences_Model_Bing);
                rblBreakSentencesModel.SelectedIndex = 0;

            }
        }

        protected void Translates_Click(object sender, EventArgs e)
        {
            DateTime startDate = DateTime.Now;
            string reVal = "";
            reVal = rblRequestModel.SelectedValue == Request_Model_Http ?
                new TranslatorByGoogleHttp().GetTranslationsByLongSentence(txtSrc.Text, ddlFrom.SelectedValue, ddlTo.SelectedValue, rblBreakSentencesModel.SelectedValue) 
                : new TranslatorByGoogleLib().GetTranslationsByLongSentence(txtSrc.Text,ddlFrom.SelectedValue, ddlTo.SelectedValue,rblBreakSentencesModel.SelectedValue);
            txtTrg.Text = Server.HtmlDecode(reVal);
            lblMsg.Text = "Uses Time : [" + (DateTime.Now - startDate).TotalMilliseconds + "]ms";
        }
    }
}